package org.example.huadianguanli.controller;

import org.apache.commons.lang3.ObjectUtils;
import org.example.core.controller.BaseController;
import org.example.core.enums.ApiResult;
import org.example.core.exception.ErrorException;
import org.example.core.mysql.Where;
import org.example.huadianguanli.model.TStorageShopModel;
import org.example.huadianguanli.service.TStorageShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * Description:
 * Date: 2024/2/15 15:16
 */
@RestController
@RequestMapping("/storage-shop")
public class TStorageShopController extends BaseController<String, TStorageShopService, TStorageShopModel> {

    @Autowired
    private TStorageShopService tStorageShopService;

    /**
     * 查询当前仓库的商品数据
     * @param params
     * @return
     */
    @GetMapping("/searchList")
    public ApiResult searchList(@RequestParam Map<String,Object> params){
        Object storageId = params.get("storageId");
        if (ObjectUtils.isEmpty(storageId)){
            throw new ErrorException("仓库id不能为空！");
        }
        List<TStorageShopModel> result = tStorageShopService.search(Where.build().field("storage_id").equal(storageId)
                .and().field("del_flag").equal(0));
        return ApiResult.success(result);
    }
}
